<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Area;
use app\common\library\Upload;

/**
 * 标准数据接口
 */
class Data extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 区域
     */
    public function area()
    {


        $AreaModel = new Area();
        $_list = $AreaModel->where('level', 2)
            ->where('status', 1)
            ->field('id,shortname,first')
            ->order('weigh asc,first asc')
//            ->limit(1)
            ->select();

        $hot = $AreaModel->where('level', 2)
            ->where('status', 1)
            ->where('is_hot', 1)
            ->field('id,shortname,first')
            ->order('weigh asc,first asc')
            ->select();

        $lat = $this->request->get('lat');
        $lng = $this->request->get('lng');
        $area_id = $this->request->get('area_id');
        $location = $area = [];
        if ($lat && $lng) {
            $location = $AreaModel->getCityFromLngLat($lng, $lat);
        }

        if ($area_id) {
            $area = $AreaModel
                ->where('status', 1)
                ->where('pid', $area_id)
                ->field('id,shortname,first')
                ->order('weigh asc,first asc')
                ->select();
        }

        $this->success('成功', ['location' => $location, 'list' => $_list, 'hot' => $hot, 'area' => $area]);
    }



    /**
     * 全站配置信息
     */
    public function config()
    {

        $site = config('site');
        $data = ['name'=>$site['name']];
        $this->success('成功', $data);
    }

}
